/**
 * @file       PageInfo.cpp
 * @brief      TODO
 * @author     Huabo Zheng
 * @date       Jan 31, 2012
 * @Copyright  2012, www.netgear.com Inc. All rights reserved.
 */

#include "PageInfo.h"

namespace NS_LCD_AFW
{

CPageInfo::CPageInfo() :
		m_iHightLightObjIndex(-1), m_iTotalPage(1), m_iCurPage(1), m_eDirection(
				UNKNOW), m_bNeedSwitchPage(true), m_bNeedUpdateView(false)
{
}

CPageInfo::~CPageInfo()
{
}

int CPageInfo::getCurPage() const
{
	return m_iCurPage;
}

int CPageInfo::getEndIndex() const
{
	TPageIndexMap::const_iterator iter = m_pageIndexMap.find(this->m_iCurPage);
	if (m_pageIndexMap.end() == iter)
	{
		return 0;
	}

	return iter->second.iEndIndex;
}

int CPageInfo::getHightLightObjIndex() const
{
	if (m_iHightLightObjIndex < 0
			|| m_iHightLightObjIndex < this->getStartIndex())
	{
		return this->getStartIndex();
	}
	else if (m_iHightLightObjIndex >= this->getEndIndex())
	{
		return this->getEndIndex() - 1;
	}
	else
	{
		return m_iHightLightObjIndex;;
	}
}

int CPageInfo::getStartIndex() const
{
	TPageIndexMap::const_iterator iter = m_pageIndexMap.find(this->m_iCurPage);
	if (m_pageIndexMap.end() == iter)
	{
		return 0;
	}

	return iter->second.iStartIndex;
}

int CPageInfo::getTotalPage() const
{
	return m_iTotalPage;
}

bool CPageInfo::isNeedSwitchPage() const
{
	return m_bNeedSwitchPage;
}

void CPageInfo::setNeedSwitchPage(bool bNeedSwitchPage)
{
	m_bNeedSwitchPage = bNeedSwitchPage;
}

void CPageInfo::setCurPage(int iCurPage)
{
	if (iCurPage < 1)
	{
		m_iCurPage = 1;
	}
	else if (iCurPage > this->m_iTotalPage)
	{
		m_iCurPage = m_iTotalPage;
	}
	else
	{
		m_iCurPage = iCurPage;
	}
}

//void CPageInfo::setEndIndex(int iEndIndex)
//{
//	m_iEndIndex = iEndIndex;
//}

void CPageInfo::setHightLightObjIndex(int iHightLightObjIndex)
{
//	if (iHightLightObjIndex < 0 || iHightLightObjIndex < this->getStartIndex())
//	{
//		m_iHightLightObjIndex = this->getStartIndex();
//	}
//	else if (iHightLightObjIndex >= this->getEndIndex())
//	{
//		m_iHightLightObjIndex = this->getEndIndex();
//	}
//	else
//	{
	m_iHightLightObjIndex = iHightLightObjIndex;
	//}
}

//void CPageInfo::setStartIndex(int iStartIndex)
//{
//	m_iStartIndex = iStartIndex;
//}

void CPageInfo::setTotalPage(int iTotalPage)
{
	m_iTotalPage = iTotalPage;
}

CPageInfo::Direction CPageInfo::getDirection() const
{
	return this->m_eDirection;
}

void CPageInfo::setDirection(Direction eDirection)
{
	this->m_eDirection = eDirection;
}

void CPageInfo::setPageInfo(int pageNo, int startIndex, int endIndex)
{
	if (startIndex >= endIndex)
	{
		endIndex = startIndex + 1;
	}
	TPageIndex pi;
	pi.iStartIndex = startIndex;
	pi.iEndIndex = endIndex;
	m_pageIndexMap[pageNo] = pi;
}

bool CPageInfo::isNeedUpdateView() const
{
	return m_bNeedUpdateView;
}

void CPageInfo::setNeedUpdateView(bool bNeedUpdateView)
{
	m_bNeedUpdateView = bNeedUpdateView;
}

bool NS_LCD_AFW::CPageInfo::isValidHightLightObjIndex() const
{
	if (m_iHightLightObjIndex >= this->getStartIndex()
			&& m_iHightLightObjIndex < this->getEndIndex())
	{
		return true;
	}
	return false;
}

}

/* namespace NS_LCD_AFW */
